<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Js 动画</title>
</head>
<style>
    .box {
        width: 60px;
        height: 40px;
        position: relative;
        left: 0;
        top: 0;
        background-color: gold;
    }
</style>

<body>

    <div class="box"></div><br/>
 <!--    <button onclick=move()>开始动</button> -->
    <script>
        const box = document.querySelector('.box');
        let left = 0; // 初始位置
        let right = 60
        function move() {
            left += 2; // 每次移动2px
            right += 2;
            box.style.left = left + 'px';
            box.style.right = right + 'px';
            if (left < 120 && right < 180) {
                requestAnimationFrame(move); // 递归调用

            }
        }
        move()
    </script>
</body>

</html>